import axios from 'axios'
import { Dialog, Toast } from 'vant';

// https://www.cyf.careoe.com:8030/
// https://192.168.1.205:8030/
const service = axios.create({
  baseURL: 'https://www.slb.careoe.com/applet', // api 的 base_url process.env.VUE_APP_BASE_API
  // baseURL: 'http://192.168.1.251/applet/',
  timeout: 1000000 // request timeout
})

// request interceptor
// service.interceptors.request.use(
//   config => {
//     if (!config.headers['X-Litemall-Token']) {
//       config.headers['X-Litemall-Token'] = `${window.localStorage.getItem(
//         'Authorization'
//       ) || ''}`;
//     }
//     return config; 
//   },
//   err => Promise.reject(err)
// )
// response interceptor
service.interceptors.response.use(
  response => {
    const res = response.data
    if (res.status == 200) {
      return response
    } else {
      Dialog.alert({
        title: '警告',
        message: '网络连接错误'
      });
    }
  }, error => {
    console.log('err' + error)
    Dialog.alert({
      title: '警告',
      message: '登录连接超时'
    });
    return Promise.reject(error)
  })

export default service
